﻿var defalutName = "销售确认单";
var data1 = [{ "name": "生产企业", "examplain": "", "statu": "未签章", "optertor": "", "date": "" },
            { "name": "石油储备公司", "examplain": "", "statu": "签章", "optertor": "", "date": "" },
            { "name": "炼油事业部", "examplain": "", "statu": "签章", "optertor": "", "date": "" },
            { "name": "生产经营管理部", "examplain": "", "statu": "未签章", "optertor": "", "date": "" }];
var data2 = [{ "name": "原油销售计划", "upman": "peiquan", "optertor": "下载" },
            { "name": "原油销售确认单", "upman": "peiquan", "optertor": "下载" },
            { "name": "原油销售成本核算单", "upman": "", "optertor": "下载" },
            { "name": "原油销售协议", "upman": "", "optertor": "下载" }];
var data3 = [{ "name": "生产企业", "examplain": "", "statu": "未签章", "optertor": "", "date": "" },
            { "name": "石油储备公司", "examplain": "", "statu": "签章", "optertor": "", "date": "" },
            { "name": "炼油事业部", "examplain": "", "statu": "签章", "optertor": "", "date": "" },
            { "name": "生产经营管理部", "examplain": "", "statu": "未签章", "optertor": "", "date": "" }];
var _index = "";
$(function () {
    _index = parseInt(getUrlPage("quanxian"));
    if (isNaN(_index)) {
        _index = 1;
    }
    var _tabList = $('.tab_menu');
    var dataimg = $('.imgClass').find('.divImg');
    for (var i = 0; i < dataimg.length; i++) {
        if (i >= _index) {
            $(dataimg[i]).hide();
        }
    }
    getdefalutTab(defalutName);
    getDateChange();
    getTabChange(defalutName);
    getInfoChange();
    $("#XSQRD").datagrid({
        fitColumns: true,
        data: data1,
        columns: [[
            { field: 'name', title: '确认方', width: 120, align: 'center' },
            { field: 'examplain', title: '说明', width: 120, align: 'center'},
            { field: 'statu', title: '状态', width: 120, align: 'center'},
            {
                field: 'optertor', title: '签章操作', width: 120, align: 'center',
                formatter: function (value, row, index) {
                    if (row.statu == "未签章")
                    {
                        return '' +
                            '<input style="width:100px;height:20px;cursor:pointer;"  type="button" id="btnQZ'+index+'" value="签章" />';
                    }
                }
            },
            { field: 'date', title: '签章时间', width: 120, align: 'center' }
        ]]
    });
    $("#YYXSXY").datagrid({
        fitColumns: true,
        data: data3,
        columns: [[
            { field: 'name', title: '确认方', width: 120, align: 'center' },
            { field: 'examplain', title: '说明', width: 120, align: 'center' },
            { field: 'statu', title: '状态', width: 120, align: 'center' },
            {
                field: 'optertor', title: '签章操作', width: 120, align: 'center',
                formatter: function (value, row, index) {
                    if (row.statu == "未签章") {
                        return '' +
                            '<input style="width:100px;height:20px;cursor:pointer;"  type="button" id="btnQZ' + index + '" value="签章1" />';
                    }
                }
            },
            { field: 'date', title: '签章时间', width: 120, align: 'center' }
        ]]
    });
    $("#XSQRD_right").datagrid({
        fitColumns: true,
        data: data2,
        columns: [[
            {
                field: 'name', title: '附件名称', width: 200, align: 'left',
                formatter: function (value, row, index) {
                     return '' +
                            '<span class="Classspan">' + row.name + ':<a href="#">' + row.name + '.pdf</a></span>';
                }
            },
            { field: 'upman', title: '上传人', width: 60, align: 'left' },
            {
                field: 'optertor', title: '操作', width: 60, align: 'left',
                formatter: function (value, row, index) {
                     return '' +
                       '<span class="Classspan"><a href="#">' + row.optertor + '</a></span>';
                }
            }
        ]]
    });
});
function getTabChange(defalutName) {
    $('.divImg').bind('click', function () {
        var self = $(this).find('span').text().trim();
        var dataImg = $('.divImg');
        for (var i = 0; i < dataImg.length; i++) {
            if ($(dataImg[i]).find('span').text().trim() != self) {
                if ($(dataImg[i]).find('span').text().trim() == defalutName) {
                    $($(dataImg[i]).find('img')[0]).removeAttr('src').attr('src', '../../images/u89.png');
                } else {
                    $($(dataImg[i]).find('img')[0]).removeAttr('src').attr('src', '../../images/u82.png');
                }
            } else {
                if ($(dataImg[i]).find('span').text().trim() == defalutName) {
                    $($(dataImg[i]).find('img')[0]).removeAttr('src').attr('src', '../../images/u76.png');
                } else {
                    $($(dataImg[i]).find('img')[0]).removeAttr('src').attr('src', '../../images/u95.png');
                }
            }
        }
        var tabList = $('.tab_menu');
        for (var i = 0; i < tabList.length; i++) {
            if ($(tabList[i]).attr('title').trim() == self) {
                if ($(tabList[i]).get(0).style.display == "none") {
                    //if ($(tabList[i]).find('.tbTable').length > 0)
                    //{
                    //    var tableData = $(tabList[i]).find('.tbTable').find('table');
                    //    var tablename = $(tableData[tableData.length - 1]).attr("id");
                    //    $("#" + tablename).datagrid(data);
                    //}
                    $(tabList[i]).get(0).style.display = "block";
                }
            } else {
                if ($(tabList[i]).get(0).style.display != "none") {
                    $(tabList[i]).get(0).style.display = "none";
                }
            }
        }
    });
}